package runthrad;

import javax.xml.bind.DatatypeConverter;
import java.util.ArrayList;

/**
 * 轮询
 * 测试多线程返回值
 * @author DELL
 * @create 2017-09-19 14:14
 */
public class TestReturnValue3 {
    public static void main(String[] args) {
        ArrayList<String> files = new ArrayList<>();
        files.add("src/file/file.txt");
        files.add("src/file/file2.txt");
        files.add("src/file/file3.txt");
        DigestThread[] digests = new DigestThread[files.size()];
        for(int i = 0; i < files.size(); i++) {
            digests[i] = new DigestThread(files.get(i));
            digests[i].start();
        }
        for (int i = 0; i < files.size(); i++) {
            while (true) {
                byte[] digest = digests[i].getDigest();
                if(digest != null) {
                    StringBuilder result = new StringBuilder(files.get(i));
                    result.append(": ");
                    result.append(DatatypeConverter.printHexBinary(digest));
                    System.out.println(result);

                    break;
                }
            }
        }
    }
}
